const app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        objectArray: [
            {
                
                id: 0,
                name: '服务类型'
              },
            {
                
              id: 1,
              name: '运力合作'
            },
            {
              id: 2,
              name: '加油服务'
            },
            {
              id: 3,
              name: '保养服务'
            },
            {
              id: 4,
              name: '充电服务'
            }
          ],
          objectIndex: 0,//默认显示位置
     
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        let that=this;
        
        wx.showShareMenu({
            menus: ['shareAppMessage', 'shareTimeline'],
            success(res) {
              console.log(res)
            },
            fail(e) {
              console.log(e)
            }
          })             
          var deviceInfo = wx.getDeviceInfo();
          console.log(deviceInfo)
          let d = app.globalData;
          this.getIndex();
          var open=wx.getStorageSync('open');  
          this.setData({
              //id:id,
              open:open,
              width:d.windowWidth,
              height:d.windowHeight,
              statusBarHeight:d.statusBarHeight,
              navHeight:d.navHeight,
              marginTop:d.navTitleTop,
              bottom:d.bottom,
              domain:d.domain,
              imgUrl:d.imgUrl,
              platform:deviceInfo.platform
          })
    },
    goBack(e){
        const pages = getCurrentPages();
          const prevPage = pages[pages.length - 2]; // 获取上一个页面实例
          console.log(prevPage);
          wx.navigateBack();
          //wx.navigateBack();
      },
      getIndex:function(){
        let that = this;    
        console.log('coupon----getIndex')  
        var store_id = wx.getStorageSync('store_id');
        var open = wx.getStorageSync('open');
        wx.request({
          url: app.globalData.domain+'/wechat/service/getCooperateIndex',
          data:{from:1,user_id:open.user_id,open_id:open.id},
          success:res=>{
              console.log(res)
              var d=res.data;
           
            that.setData({
                objectArray:d.obj,
                objectIndex:0
         

            })
          }
      })

    },
   bindPickerChange(e){
        var index = e.detail.value;
        console.log(index);
        this.setData({
            objectIndex:index
        })
   },
   inputName(e){
    var value = e.detail.value;
    this.setData({
        name:value
    })
},
inputPhone(e){
    var value = e.detail.value;
    this.setData({
        phone:value
    })
},
toSubmit:function(){
    let that = this;    
    let d = this.data;
    console.log('coupon----getIndex')  
    var store_id = wx.getStorageSync('store_id');
    var open = wx.getStorageSync('open');
    var index = d.objectIndex;
    var obj =  d.objectArray;
    var type = obj[index].id
    wx.request({
      url: app.globalData.domain+'/wechat/service/toCooperate',
      data:{from:1,user_id:open.user_id,open_id:open.id,phone:d.phone,name:d.name,typ:type},
      success:res=>{
          console.log(res)
          var d=res.data;
      
        app.showModal(d.msg,'#','#');
        wx.navigateBack();
      }
  })

},
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})